import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
const resolve = (dir: string) => path.join(__dirname, dir)

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [
        AntDesignVueResolver({ importStyle: 'less' }),
      ],
    }),
    Components({
      resolvers: [
        AntDesignVueResolver({ importStyle: 'less' }),
      ],
    }),
  ],
  resolve: {
      alias: {
        '@': resolve('src'),
        '@comps': resolve('src/components'),
        '@apis': resolve('src/apis'),
        '@views': resolve('src/views'),
        '@router': resolve('src/router'),
        '@layout': resolve('src/layout'),
      }
  },
  server: {
    port: 8080,
    strictPort: false,
    open: true,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
